package com.woke.adapter;

import java.util.ArrayList;
import java.util.List;

import cn.xl.xxl.imagecache.ImageLoader;

import com.zhongcai.online.R;
import com.woke.data.Datas_myzhongc1;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class Myzhongcdadter extends BaseAdapter{
	private LayoutInflater mInflater;
	private List<Datas_myzhongc1> datalist;
	private ImageLoader imageLoader;
	private int phonewid;

	public Myzhongcdadter(LayoutInflater minflater, ArrayList<Datas_myzhongc1> datalist,
			ImageLoader imageLoader, int phonewid) {
		this.mInflater = minflater;
		this.datalist = datalist;
		this.imageLoader = imageLoader;
		this.phonewid = phonewid;
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return datalist.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}
	
	class Holder {
		TextView mTpaytype;
		TextView mTname;
		TextView mTtype;
		TextView mTmoney;
		TextView mTid,mTstas;
		ImageView imgesinle;
		
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Holder holder = null;
		if(convertView == null){
			holder = new Holder();
			convertView = mInflater.inflate(R.layout.item_adter_myzhongc, null);
			holder.mTtype = (TextView)convertView.findViewById(R.id.item_myzhongc_texttype);
			holder.mTname = (TextView)convertView.findViewById(R.id.item_myzhongc_textname);
			holder.mTmoney = (TextView)convertView.findViewById(R.id.item_myzhongc_money);
			holder.mTid = (TextView)convertView.findViewById(R.id.item_myzhongc_id);
			holder.mTpaytype = (TextView)convertView.findViewById(R.id.item_myzhongc_paytype);
			holder.mTstas = (TextView) convertView.findViewById(R.id.item_myzhongc_stats);
			holder.imgesinle = (ImageView) convertView.findViewById(R.id.item_myzhongc_image);
			convertView.setTag(holder);
		}else{
			 holder = (Holder) convertView.getTag();
		}
//		type�ڳ�����1��Ʒ2��Ȩ3���� product_img�ڳ���ͼ product_name�ڳ���Ŀ��
//product_status�ڳ�״̬1Ϊδ���2Ϊ�����3Ϊ�ѷ���4Ϊ�����money���id�������
//status ����״̬1Ϊ�Ѹ��2Ϊ�ѷ�����3Ϊ�����
		Datas_myzhongc1 data = datalist.get(position);
		if(data.getType().equals("1")){
			holder.mTtype.setText("产品");
		}if(data.getType().equals("2")){
			holder.mTtype.setText("股权");
		}if(data.getType().equals("3")){
			holder.mTtype.setText("慈善");
		}
		LayoutParams params = holder.imgesinle.getLayoutParams();
		params.width = phonewid / 3;
		params.height = phonewid / 3;
		holder.imgesinle.setLayoutParams(params);
		imageLoader.DisplayImage("http://"+data.getProduct_img(), holder.imgesinle, false, false, false,0);
		holder.mTname.setText(data.getProduct_name());
		holder.mTmoney.setText("支持金额：  ￥"+data.getMoney());
		if(data.getStatus().equals("1")){
			holder.mTstas.setText("已付款");
		}if(data.getStatus().equals("2")){
			holder.mTstas.setText("已发货");
		}if(data.getStatus().equals("3")){
			holder.mTstas.setText("已完成");
		}
		holder.mTid.setText("订单编号： "+data.getId());
		if(data.getProduct_status().equals("1")){
			holder.mTpaytype.setText("众筹状态：  未审核");
		}if(data.getProduct_status().equals("2")){
			holder.mTpaytype.setText("众筹状态：  已审核");
		}if(data.getProduct_status().equals("3")){
			holder.mTpaytype.setText("众筹状态：  已反售");
		}if(data.getProduct_status().equals("4")){
			holder.mTpaytype.setText("众筹状态：  已完成");
		}
		
		return convertView;
	}
}
